var _            = require('lodash');
var PublishConfigProxy    = require('../../proxy/publish_cfg.js');
var EventProxy    = require('eventproxy');
var logger              = require('log4js').getLogger();

exports.addPublishConfig = function(req, res, next){
    var cfg_info = req.body;
    PublishConfigProxy.addPublishConfig(cfg_info,function(err, data){
        if(err){
            logger.error(err);
            return res.format_json(null,500,err);
        }
        return res.format_json(data);
    });
};

exports.getPublishConfig = function(req, res, next){
    var cfg_id = req.params.publishConfig_id;
    PublishConfigProxy.getPublishConfig(cfg_id,function(err, data){
        if(err){
            logger.error(err);
            return res.format_json(null,500,err);
        }
        return res.format_json(data);
    });
};

exports.deletePublishConfig = function(req, res, next){
    var cfg_id = req.params.publishConfig_id;
    PublishConfigProxy.deletePublishConfig(cfg_id,function(err, data){
        if(err){
            logger.error(err);
            return res.format_json(null,500,err);
        }
        return res.format_json({success:true});
    });
};

exports.editPublishConfig = function(req, res, next){
    var cfg_info = req.body;
    var cfg_id = req.params.publishConfig_id;
    PublishConfigProxy.editPublishConfig(cfg_id,cfg_info,function(err, data){
        if(err){
            logger.error(err);
            return res.format_json(null,500,err);
        }
        return res.format_json({success:true});
    });
};

exports.getGoodsInfo = function(req, res, next){
    config_id = req.params.config_id;
    PublishConfigProxy.getGoodsInfo(config_id,function(err, data){
        if(err){
            logger.error(err);
            return res.format_json(null,500,err);
        }
        return res.format_json(data);
    });
};
exports.getList = function(req, res, next){
  PublishConfigProxy.all(function(err, data){
    if(err){
      loggr.error(err);
      return res.format_json(null, 500, err);
    }
    return res.format_json(data);
  });
};
